#include <iostream>
#include <cstring>
#include "mypolis/polynomial.h"
#include "mypolis/term.h"

int demo(){
    Term t1("2x^4");
    std::cout << "t1(\"2x^4\") = " << t1 << std::endl;
    Term t2(3, 4);
    std::cout << "t2(3,4) = " << t2 << std::endl;
    Term t3;
    t3 = t1 + t2;
    std::cout << "t3(t2 + t1) = " << t3 << std::endl;

    Polynomial p1("-7x^2 + 2x^0");
    std::cout << "p1(\"-7x^2 + 2x^0\") = " << p1 << std::endl;
    Term t4(4, 3);
    Polynomial p2(t4);
    std::cout << "p2(t4(4,4)) = " << p2 << std::endl;
    Polynomial p3 = p1 + p2;
    std::cout << "p3(p1 + p2) = " << p3 << std::endl;

    Term t5(-1, 3);
    Term t6(-2, 2);
    Polynomial p4(t5);
    std::cout << "p4(t5(-1,3)) = " << p4 << std::endl;
    p4 += t6;
    std::cout << "p4(+= t6(-2,2)) = " << p4 << std::endl;
    p4 *= p3;
    std::cout << "p4(*= p3) = " << p4  << std::endl;
    return 1;
}

int interactive(){
    Term t1;
    std::cout << "Enter term t1: ";
    std::cin >> t1;
    Term t2;
    std::cout << "Enter term t2: ";
    std::cin >> t2;
    Term t3;
    t3 = t1 + t2;
    std::cout << "t3(t1 + t2) = " << t3 << std::endl;

    Polynomial p1;
    std::cout << "Enter poly p1: " << std::endl;
    std::cin >> p1;
    Polynomial p2(t2);
    std::cout << "p2(t2) = " << p2 << std::endl;
    Polynomial p3 = p1 + p2;
    std::cout << "p3(p1 + p2) = " << p3 << std::endl;
    p3 *= p1;
    std::cout << "p3(*= p1) = " << p3 << std::endl;
    return 1;
}

int main(int argc, char *argv[]) {
    setlocale(LC_ALL, "Russian");

    bool isInteractive = false;
    if ((argc == 2) && strcmp(argv[1], "i") == 0) {
        isInteractive = true;
    }
    if (isInteractive) {
        return interactive();
    } else {
        return demo();
    }
}